package com.zjq.springsocial.renren.api.impl;

import org.springframework.web.client.RestTemplate;

import com.zjq.springsocial.renren.api.GraphApi;
import com.zjq.springsocial.renren.api.RenrenEntity;
import com.zjq.springsocial.renren.api.User;
import com.zjq.springsocial.renren.api.UserOperations;

public class UserTemplate extends AbstractRenrenOperations implements UserOperations{
	
	private final GraphApi graphApi;
	
	private RestTemplate restTemplate;
	
	public UserTemplate(GraphApi graphApi,RestTemplate restTemplate,boolean isAuthorized) {
		super(isAuthorized);
		this.graphApi = graphApi;
		this.restTemplate = restTemplate;
	}

	@Override
	//https://api.renren.com/v2/user/get?access_token={access_token}&={userId}
	public User getUser(Long id) {
		requireAuthorization();
		RenrenEntity entity = restTemplate.getForObject(buildUri("v2/user/get","userId",String.valueOf(id)), RenrenEntity.class);
		return entity.getUser();
	}

	@Override
	public User getUser() {
		requireAuthorization();
		RenrenEntity entity = restTemplate.getForObject(buildUri("v2/user/login/get"), RenrenEntity.class);
		return entity.getUser();
	}

}
